﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GMS.BIZ;
using System.Data;

namespace Web.Paper
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!((Account)Session["Account"]).RoleCurrent.Equals('s')) Response.Redirect("Default.aspx");
            Student myStudent = (Student)Session["Student"];
            if (((Student)Session["Student"]).StudentName == "")
                Response.Redirect("~/Information/StuInformation.aspx");
            PaperInfo myPaperInfo=new PaperInfo();
            myPaperInfo = myStudent.Papers.GetPaperInfo();
            if (myPaperInfo == null)
                Label_NoData1.Text = "你还没有论文信息";
            int doc1 = (int)myPaperInfo.Doc1status;
            int doc2 = (int)myPaperInfo.Doc2status;
            int doc3 = (int)myPaperInfo.Doc3status;
            int doc4 = (int)myPaperInfo.Doc4status;
            int doc5 = (int)myPaperInfo.Doc5status;
            int doc6 = (int)myPaperInfo.Doc6status;

            Label_LTSB.Text = DocumentStatus.GetName(doc1);
            Label_RWS.Text = DocumentStatus.GetName(doc2);
            Label_KTBG.Text = DocumentStatus.GetName(doc3);
            Label_ZP.Text = DocumentStatus.GetName(doc4);
            Label_LW.Text = DocumentStatus.GetName(doc5);
            Label_FY.Text = DocumentStatus.GetName(doc6);
            if (myStudent.Papers.PaperTitle == "")
            {
                Label_oldpapertitle1.Text = "未提交";
                ImageButton_Add.Visible = true;
                ImageButton_papertitleEdit.Visible = false;
            }
            else
            {
                Label_oldpapertitle1.Text = myStudent.Papers.PaperTitle;
                ImageButton_papertitleEdit.Visible = true;
                ImageButton_Add.Visible = false;
            }
           
           
            //获得答辩教师 
            Label_guidetch.Text = Staff.GetName(myStudent.Papers.TeacherID.ToString());
            //获得PaperInfo
            DataSet ds = Defense.GetDefenseList(myStudent.StudentID);
            if (ds != null)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    ds.Tables[0].Rows[i]["def_assistant"] = Staff.GetName(ds.Tables[0].Rows[i]["def_assistant"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_1"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_1"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_2"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_2"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_3"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_3"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_4"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_4"].ToString());
                    ds.Tables[0].Rows[i]["def_tch_5"] = Staff.GetName(ds.Tables[0].Rows[i]["def_tch_5"].ToString());
                }


                GridView_PDefenseLib.DataSource = ds;
                GridView_PDefenseLib.DataBind();
            }
            else Label_NoData2.Text = "你还没有答辩信息";
            
        }
        //修改论文题目
        protected void ImageButton_papertitleEdit_Click(object sender, ImageClickEventArgs e)
        {
            Student myStudent = (Student)Session["Student"];
            string ok = myStudent.Papers.SetPaperTitle(TextBox_papertitle.Text.ToString());
            if (ok != Resources.ErrorMessage.OK) Label_papertitleResult.Text = "修改论文题目未成功";
            Label_papertitleResult.Text = "论文题目已修改";

            PaperInfo myPaperInfo = new PaperInfo();
            myPaperInfo = myStudent.Papers.GetPaperInfo();
            if (myPaperInfo == null)
                Label_NoData1.Text = "你还没有论文信息";
            int doc1 = (int)myPaperInfo.Doc1status;
            int doc2 = (int)myPaperInfo.Doc2status;
            int doc3 = (int)myPaperInfo.Doc3status;
            int doc4 = (int)myPaperInfo.Doc4status;
            int doc5 = (int)myPaperInfo.Doc5status;
            int doc6 = (int)myPaperInfo.Doc6status;

            Label_LTSB.Text = DocumentStatus.GetName(doc1);
            Label_RWS.Text = DocumentStatus.GetName(doc2);
            Label_KTBG.Text = DocumentStatus.GetName(doc3);
            Label_ZP.Text = DocumentStatus.GetName(doc4);
            Label_LW.Text = DocumentStatus.GetName(doc5);
            Label_FY.Text = DocumentStatus.GetName(doc6);
            Label_oldpapertitle1.Text = myStudent.Papers.PaperTitle;

        }
        //添加论文题目
        protected void ImageButton_Add_Click(object sender, ImageClickEventArgs e)
        {
            Student myStudent = (Student)Session["Student"];
            string ok = myStudent.Papers.SetPaperTitle(TextBox_papertitle.Text.ToString());
            if (ok != Resources.ErrorMessage.OK) Label_papertitleResult.Text = "修改论文题目未成功";
            Label_papertitleResult.Text = "论文题目已修改";

            PaperInfo myPaperInfo = new PaperInfo();
            myPaperInfo = myStudent.Papers.GetPaperInfo();
            if (myPaperInfo == null)
                Label_NoData1.Text = "你还没有论文信息";
            int doc1 = (int)myPaperInfo.Doc1status;
            int doc2 = (int)myPaperInfo.Doc2status;
            int doc3 = (int)myPaperInfo.Doc3status;
            int doc4 = (int)myPaperInfo.Doc4status;
            int doc5 = (int)myPaperInfo.Doc5status;
            int doc6 = (int)myPaperInfo.Doc6status;

            Label_LTSB.Text = DocumentStatus.GetName(doc1);
            Label_RWS.Text = DocumentStatus.GetName(doc2);
            Label_KTBG.Text = DocumentStatus.GetName(doc3);
            Label_ZP.Text = DocumentStatus.GetName(doc4);
            Label_LW.Text = DocumentStatus.GetName(doc5);
            Label_FY.Text = DocumentStatus.GetName(doc6);
            Label_oldpapertitle1.Text = myStudent.Papers.PaperTitle;
        }
    }
}
